package com.webside.front.common.controller;

import java.io.UnsupportedEncodingException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/**
 * 用来做请求转发的controller
 * @author xuanzhen
 *
 */
@Controller
@Scope("prototype")
@RequestMapping(value = "/common/")
public class UtilController {
	
	//转发
	@RequestMapping(value="/redirect",method=RequestMethod.GET)
	public ModelAndView redictRequest(ModelAndView model,
			@RequestParam(value="id",defaultValue="1",required=true)Integer id,
			@RequestParam(value="source",required=false)String source, 
			@RequestParam(value="channel",defaultValue="TVPLAY",required=true)String channel){
		try {
			source = new String(source.getBytes("iso-8859-1"),"UTF-8");
			System.out.println("测试来源："+source);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	    if (source != null && source.equals("电信CMS")||source.equals("")) {
	    	Integer seriesId = id;
	    	if (channel.equals("INFORMATION")) {
	    		model.addObject("youkuId",seriesId);
	    		model.addObject("channel",channel);
	    		model.setViewName("redirect:../public/detail/shows.html");
	    	}else{
	    	model.addObject("seriesId", seriesId);
	    	model.addObject("setNum","1");
				model.setViewName("redirect:../public/detail/show.html");
			}
	    }else{
			model.addObject("id",id);
			if (channel.equals("INFORMATION")) {
	    		model.addObject("youkuId",id);
	    		model.addObject("seriesId", "");
	    		model.addObject("setNum", "");
	    		model.setViewName("redirect:../public/detail/shows.html");
			}else{
				model.setViewName("redirect:../detail/grabvideo.html");
			}
		}
	    
	     return model;
	}
	
}
